
class Student {

    {
        this.name = "zhangsan";
        System.out.println("实例代码块！");
        //构造代码块：定义在类当中（不加修饰符）。也叫实例代码块
        //构造代码块一般初始化实例成员变量
    }
    private String name = "lisa";
    private int age;

    static {
        classRoom = 301;
        //静态代码块只能初始化静态成员变量
        System.out.println("静态代码块 静态代码块只能初始化静态成员变量");
    }
    public static int classRoom = 209;

    public Student() {
        System.out.println("调用不带参数的构造方法！");
        //此时我们的构造块里面的初始化就起到了作用
    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("调用了带两个参数的构造方法！");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public void print() {
        System.out.println("姓名："+name+ " 年龄："+age);
    }
}
public class Test {
    public static void main(String[] args) {

        Student student1 = new Student("zhangsan",18);
        student1.print();
        System.out.println("============");
        //Student student2 = new Student();

        //System.out.println(student.getName());

        //System.out.println(Student.classRoom);//此时这就是我们加载类了
        //在这个情况下我们只有加载静态代码块
        /*{
            System.out.println("这就是一个普通代码块");
        }

        //Student student = new Student("lisi",17);
        Student student = new Student();
        //此时我们调用的是不带参数的狗构造方法*/
    }

}
/*public class Test2 {
    public int aMethod(){
        static int i = 0;//static 只能修饰成员变量，不能修饰局部变量
        i++;
        return i;
    }
    public static void main(String args[]){
        Test2 test = new Test2();
        test.aMethod();
        int j = test.aMethod();
        System.out.println(j);
    }
}*/


 /* public class Test3 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            Data data = new Data(x, y);
            System.out.println(data.getX() + data.getY());
        }
    }
    }*/
/*class Data {

    private int x;
    private int y;

    public Data(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

}*/

